package game.ouroboros.magic;

import java.util.ArrayList;
import java.util.List;

import game.ouroboros.*;
import game.ouroboros.traps.Trap;

public class ProjectileManager implements MapPositions {

	private Projectile[][] projectileMap;
	public int sizeX;
	public int sizeY;
	public int rows;
	public int cols;

	private int positions[][] = new int[10][2];
	public boolean[][] map;
	private List<Projectile> projeteis;

	public ProjectileManager(int sizeX, int sizeY, int rows, int cols) {
		this.cols = cols;
		this.rows = rows;
		this.sizeX = sizeX;
		this.sizeY = sizeY;
		projectileMap = new Projectile[rows][cols];
		map = new boolean[rows][cols];
		this.projeteis = new ArrayList<Projectile>(3);
	}

	public boolean putProjectileInXY(Projectile p, float x, float y) {
		int posX = (int) (x / sizeX);
		int posY = (int) (x / sizeY);
		p.position.x = x;
		p.position.y = y;
		int count = 0;
		while (positions[count][0] != -1) {
			projectileMap[positions[count][0]][positions[count][1]] = p;
			count++;
		}
		projeteis.add(p);
		return true;
	}


	public Projectile getProjectileAt(int x, int y) {
		try {
			return projectileMap[x / sizeX][y / sizeY];
		} catch (Exception e) {
			return null;
		}
	}
	
	public boolean isFree(float x, float y) {
		try {
			return map[(int) (x / sizeX)][(int) (y / sizeY)];
		} catch (Exception e) {
			return false;
		}
	}

	@Override
	public boolean[][] getMap() {
		return this.map;
	}
	
	public List<Projectile> getProjeteis() {
		return this.projeteis;
	}

	@Override
	public List<Trap> getObjetivos() {
		// TODO Auto-generated method stub
		return null;
	}
}